<?php

if(!defined('DEDEINC')) exit('Request Error!');
include_once DEDEINC.'/channelunit.func.php';

function plus_ztlist(&$atts,&$refObj,&$fields)
{
	global $dsql,$_vars,$envs;
	//zl参数为是否取二级栏目以下三级栏目的文章，值为1或0
	$attlist = "typeid=0,row=10,limit=0,flag=0,noflag=0,titlelen=30,sort=pubdate,orderway=desc,infolen=50,cuttitle=0,keyword=,zl=0";
	FillAtts($atts,$attlist);
	FillFields($atts,$fields,$refObj);
	extract($atts, EXTR_OVERWRITE);
	//flag属性处理
	$flag = $flag=="0"?"":trim($flag);
	$flagsql="";
	if(!strchr($flag,',') && $flag != "")$flagsql = " and arc.flag like '%".$flag."%'";
	else if(strchr($flag,',')){
		 $flaglimits = explode(',',$flag);
		 foreach($flaglimits as $flaglimit)
		 	{
			 	$flagsql.=" and arc.flag like '%".$flaglimit."%'";
			}
		 }
	//$flagsql =	$flag=="0"?"":" and arc.flag like '%".$flag."%'";
	//noflag属性处理 
	$noflag = $noflag=="0"?"":trim($noflag);
	$noflagsql="";
	if(!strchr($noflag,',') && $noflag != "" && !strchr($flag,$noflag))$noflagsql = " and arc.flag not like '%".$noflag."%'";
	else if(strchr($noflag,','))
		  {
			  $noflagarrays = explode(',',$noflag);
			  foreach($noflagarrays as $noflagarray)
			  {
				  if(!strchr($flag,$noflagarray)) $noflagsql .= " and arc.flag not like '%".$noflagarray."%'";
				  else {$noflagsql="";break;}
			  }
		  }
	//处理keyword属性
	if($keyword!='')
	{
		$keyword=trim($keyword);
		if(strchr($keyword,','))
		{
			$keywordarrays=explode(',',$keyword);
			foreach($keywordarrays as $keywordarray)
			{
				$keywordstr.=" or arc.keywords like '%".$keywordarray."%'";
			}
		}
		else $keywordstr=" and arc.keywords like '%".$keyword."%'";
	}
	//处理limit属性
	//$limit = $limit == -1 ? '':$limit;
	if($limit != "0")
	{
	 $limit = trim($limit);
	 $row = ' limit '.$limit;
	}
	else $row = ' limit '.$row;
	if($typeid=='all')$typestr='';
	else if($zl == 1) {
		$query="Select id from #@__arctype where reid in ($typeid)";
		$dsql->SetQuery($query);
		$dsql->Execute("an");
		while($rowarray = $dsql->GetArray('an')){$rows[]=$rowarray['id'];}
		$typeidstr = implode(",",$rows);
		$rowarray='';
		if($typeidstr!='')$typestr=' and arc.typeid in ('.$typeidstr.') ';
		else $typestr=' and arc.typeid in ('.$typeid.') ';
	}else $typestr=' and arc.typeid in ('.$typeid.') ';
	$query = "Select arc.*,addo.redirecturl,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,
			tp.moresite,tp.siteurl,tp.sitepath from `#@__archives` arc left join `#@__arctype` tp on arc.typeid=tp.id left join `#@__addonarticle` addo on arc.id=addo.aid where arc.arcrank >= 0 $typestr ".$flagsql." ".$noflagsql." ".$keywordstr." order by $sort $orderway $row ";
//echo $query;
	$dsql->SetQuery($query);
	$dsql->Execute("an");
	$artlist = array();
	$icoun = 1;
	while($row = $dsql->GetArray('an'))
	{	
	    if($cuttitle==1){
			$arr=explode(" ",$row['title']);
			$row['title1']=cn_substr($arr[0].$arr[1],12);
			$row['title2']=cn_substr($arr[2],12);
			$row['title3']=cn_substr($arr[3],12);		
		}else if($cuttitle==2){
			$arr=explode(" ",$row['title']);
			if(strlen($arr[0])==3)
			{	
				$row['title11']=$arr[0]." ".$arr[1];
				$row['title12']=cn_substr($arr[3],24);
			}
			else
			{
				$row['title11']=cn_substr($arr[0],12);
				$row['title12']=cn_substr($arr[1],24);
			}
		}		
		$row['arcurl'] = GetFileUrl($row['id'],$row['typeid'],$row['senddate'],$row['title'],1,0,$row['namerule'],$row['typedir'],0,$row['filename'],$row['moresite'],$row['siteurl'],$row['sitepath']);

		$row['arcurl'] = $row['redirecturl']==""?$row['arcurl']:$row['redirecturl'];
		
		$row['typeurl'] = GetTypeUrl($row['typeid'],$row['typedir'],$row['isdefault'],$row['defaultname'],$row['ispart'],
		$row['namerule2'],$row['moresite'],$row['siteurl'],$row['sitepath']);

		if($row['litpic'] == '-' || $row['litpic'] == '')
		{
			$row['litpic'] = $GLOBALS['cfg_cmspath'].'/images/defaultpic.gif';
		}
		if(!eregi("^http://",$row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y')
		{
			$row['litpic'] = $GLOBALS['cfg_mainsite'].$row['litpic'];
		}
		$row['picname'] = $row['litpic'];
		
		$row['image'] = "<img src='".$row['picname']."' border='0' alt='".ereg_replace("['><]","",$row['title'])."' />";
		$row['imglink'] = "<a href='".$row['filename']."'>".$row['image']."</a>";

		$row['info']=$row['description']= cn_substr_utf8($row['description'],$infolen);
		//$PreNext['title']=cn_substr($PreNext['title'],4);
		$row['stime'] = GetDateMK($row['pubdate']);
		$row['typelink'] = "<a href='".$row['typeurl']."'>".$row['typename']."</a>";
		$row['fulltitle'] = $row['title'];
		$row['title'] = cn_substr_utf8($row['title'],$titlelen);
		$titlearray = explode(' ',$row['fulltitle']);
		$row['title1'] = $titlearray[0];
		$row['textlink'] = "<a href='".$row['filename']."'>".$row['title']."</a>";
		$row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
		$row['memberurl'] = $GLOBALS['cfg_memberurl'];
		$row['templeturl'] = $GLOBALS['cfg_templeturl'];
		$row['autoindex'] = $icoun++;	
		$artlist[] = $row;
	}
	return $artlist;
}

?>